package cn.cqautotest.cqviehelper.presenter;

import android.speech.tts.TextToSpeech;

import cn.cqautotest.cqviehelper.base.BaseApplication;

import java.util.Locale;

public class SpeakPresenter implements TextToSpeech.OnInitListener {

    private static volatile SpeakPresenter singleton = null;
    private final TextToSpeech mTextToSpeech;

    private SpeakPresenter() {
        mTextToSpeech = new TextToSpeech(BaseApplication.getContext(), this);
    }

    public static SpeakPresenter getInstance() {
        if (singleton == null) {
            synchronized (SpeakPresenter.class) {
                if (singleton == null) {
                    singleton = new SpeakPresenter();
                }
            }
        }
        return singleton;
    }

    public TextToSpeech getTextToSpeech() {
        return mTextToSpeech;
    }

    @Override
    public void onInit(int status) {
        mTextToSpeech.setLanguage(Locale.CHINA);
    }

    public void shutdown() {
        mTextToSpeech.stop();
        mTextToSpeech.shutdown();
    }
}
